package edu.webtek.cloudresp;

import org.jdom2.Document;
import org.jdom2.Element;


public class RespCreateCustomer extends RespBase{
	private final int     customerID;
	private final boolean usernameTaken;
	
	public int getCustomerID() {
		return customerID;
	}

	public RespCreateCustomer(Document resp) {
		int   customerID = -1;
		boolean usernameTaken = false;
		if(resp == null){
			this.usernameTaken = usernameTaken;
			this.customerID   = customerID;
			flagResponseError();
			return;
		}
		
		for(Element attr : resp.getRootElement().getChildren()){
			switch(attr.getName()){
			case "customerID":
				customerID = Integer.parseInt(attr.getText());
				break;
			case "usernameTaken":
				usernameTaken = true;
				break;
			}
		}
		
		this.usernameTaken = usernameTaken;
		this.customerID   = customerID;
	}
	
	
	@Override
	public boolean hadError(){
		return(usernameTaken);
	}
	@Override
	public String getErrorString(){
		if(usernameTaken) return "Username is taken";
		return super.getErrorString();
	}
}
